Previous: Scripts, Up: Commands


3.6 Built-in commands

Several commands are built-in in Eshell. In order to call the external variant of a built-in command foo, you could call *foo. Usually, this should not be necessary. You can check what will be applied by the which command:

     ~ $ which ls
     eshell/ls is a compiled Lisp function in `em-ls.el'
     ~ $ which *ls
     /bin/ls

If you want to discard a given built-in command, you could declare an alias, Aliases. Eample:

     ~ $ which sudo
     eshell/sudo is a compiled Lisp function in `em-unix.el'
     ~ $ alias sudo '*sudo $*'
     ~ $ which sudo
     sudo is an alias, defined as "*sudo $*"

Some of the built-in commands have a special behaviour in Eshell:

cd
This command changes the current working directory. Usually, it is invoked as ‘cd foo’ where foo is the new working directory. But cd knows about a few special arguments:

When it receives no argument at all, it changes to the home directory.

Giving the command ‘cd -’ changes back to the previous working directory (this is the same as ‘cd $-’).

The command ‘cd =’ shows the directory stack. Each line is numbered.

With ‘cd =foo’, Eshell searches the directory stack for a directory matching the regular expression ‘foo’ and changes to that directory.

With ‘cd -42’, you can access the directory stack by number.

history
The ‘history’ command shows all commands kept in the history ring as numbered list. If the history ring contains eshell-history-size commands, those numbers change after every command invocation, therefore the ‘history’ command shall be applied before using the expansion mechanism with history numbers.

The n-th entry of the history ring can be applied with the ‘!n’ command. If n is negative, the entry is counted from the end of the history ring.

!foo’ expands to the last command beginning with foo, and ‘!?foo’ to the last command containing foo. The n-th argument of the last command beginning with foo is accessible by !foo:n.

su
sudo
su and sudo work as expected: they apply the following commands (su), or the command being an argument (sudo) under the permissions of somebody else.

This does not work only on the local host, but even on a remote one, when default-directory is a remote file name. The necessary proxy configuration of Tramp is performed automatically. Example:

          ~ $ cd /ssh:otherhost:/etc
          /ssh:user@otherhost:/etc $ sudo find-file shadow